﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Text.RegularExpressions;

public partial class site : System.Web.UI.MasterPage
{
    private TranslatorContainer context;
    private System.Data.Services.Client.DataServiceQuery<Translation> var1;
    private string[] resul;
    protected void Page_Load(object sender, EventArgs e)
    {

        if (IsPostBack) {


            Uri serviceUri = new Uri("https://api.datamarket.azure.com/Bing/MicrosoftTranslator/");

            context = new TranslatorContainer(serviceUri);
            context.Credentials = new NetworkCredential("MyAppPri", "pzDmkdU+TX5yoez1zCZvvsGaD8KyrSyZGoo+zZC6ZKw=");



            var1 = context.Translate(TextBox1.Text, DropDownList1.SelectedValue, DropDownList2.SelectedValue);
            string s = var1.ToString();
            WebClient client = new WebClient();
            client.Credentials = new NetworkCredential("sousadax@hotmail.com", "Az3QKK5iC/6JP5YdR+mKSwzo+tIPHtQuSERciyzEC0w=");
            string results = client.DownloadString(s);



            resul = Regex.Split(results, @"<d:Text.*>(.*)</d:Text>");


            //richTextBox1.AppendText(output.ToString());


            //results.Split('<d:Text m:type="Edm.String">')
            Label3.Text = resul[1];
        }

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        
        Uri serviceUri = new Uri("https://api.datamarket.azure.com/Bing/MicrosoftTranslator/");

        context = new TranslatorContainer(serviceUri);
        context.Credentials = new NetworkCredential("MyAppPri", "pzDmkdU+TX5yoez1zCZvvsGaD8KyrSyZGoo+zZC6ZKw=");



        var1 = context.Translate(TextBox1.Text, DropDownList1.SelectedValue, DropDownList2.SelectedValue);
        string s = var1.ToString();
        WebClient client = new WebClient();
        client.Credentials = new NetworkCredential("sousadax@hotmail.com", "Az3QKK5iC/6JP5YdR+mKSwzo+tIPHtQuSERciyzEC0w=");
        string results = client.DownloadString(s);



        resul = Regex.Split(results, @"<d:Text.*>(.*)</d:Text>");


        //richTextBox1.AppendText(output.ToString());


        //results.Split('<d:Text m:type="Edm.String">')
        Label3.Text = resul[1];
        
    }
}
